from datetime import datetime

import dotenv

from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI, OpenAI

dotenv.load_dotenv()

# 1.编排prompt
prompt = ChatPromptTemplate.from_messages([
    ("system", "你是个AI机器人，根据用户的提问回答"),
    ("human", "{query}")
]).partial(now=datetime.now())

# 2. 创建大语言模型
llm = ChatOpenAI(temperature=0.9, model_name="kimi-k2-0711-preview")

ai_message = llm.invoke(prompt.invoke({"query": "请讲一个程序员的冷笑话"}))

print(ai_message.type)
print(ai_message.content)
print(ai_message.response_metadata)
